<?php

namespace Drupal\s_commerce_service\Entity;

use Drupal\s_commerce_service\ViewsController\Traits\SCommerceServiceAmountRefundTypeTrait;
use Drupal\s_commerce_service\ViewsController\Traits\SCommerceServiceReceiptTrait;
use Drupal\s_commerce_service\ViewsController\Traits\SCommerceServiceStatusTrait;
use Drupal\s_commerce_service\ViewsController\Traits\SCommerceServiceTypeTrait;
use Entity;

class SCommerceService extends Entity {

  public $id;

  public $vid;

  public $uid;

  public $op_uid;

  public $created;

  public $changed;

  public $is_new_revision;

  public $store_id = 0;

  public $order_id = 0;

  public $line_item_id = 0;

  public $type = 0;

  public $receipt = 0;

  public $amount = 0;

  public $amount_refund_type = 's_commerce_service_none';

  public $reason = 0;

  public $receipt_number = 1;

  public $reason_desc;

  public $status = 0;

  public $shipping_type;

  public $shipping_number;

  use SCommerceServiceStatusTrait;
  use SCommerceServiceTypeTrait;
  use SCommerceServiceReceiptTrait;
  use SCommerceServiceAmountRefundTypeTrait;

  function __construct($values = []) {
    $this->is_new_revision = TRUE;
    parent::__construct($values, 's_commerce_service');
  }

  public function save() {
    $this->changed = REQUEST_TIME;
    if (empty($this->created)) {
      $this->created = REQUEST_TIME;
    }

    $this->op_uid = $GLOBALS['user']->uid;
    if (empty($this->uid)) {
      $this->uid = $GLOBALS['user']->uid;
    }

    return parent::save();
  }

}
